package com.sinevil.tcpTrans.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * @Classname FileUtil
 * @Description TODO
 * @Version 1.0.0
 * @Date 2025/3/1 23:35
 * @Created by sinevil
 */
public class FileUtil {

    /**
     * 确保目录存在
     * @param path 目录
     */
    public static void ensureDirectoryExists(Path path) {
        try {
            if (!Files.exists(path)) {
                Files.createDirectories(path);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to create directory: " + path, e);
        }
    }

    /**
     * 确保文件存在
     * @param path 文件
     */
    public static void ensureFileExists(Path path) {
        try {
            if (!Files.exists(path)) {
                Files.createFile(path);
            }
        } catch (IOException e) {
            throw new RuntimeException("Failed to create file: " + path, e);
        }
    }
}